﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using CustomControls;

namespace Editor.ModeToolbars
{
    [DesignerCategory("code")]
    [ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip | ToolStripItemDesignerAvailability.StatusStrip)]
    //[Designer(typeof(ToolStripTabControlDesigner), typeof(IRootDesigner))]
    public class ToolStripTabControl : ToolStripControlHost
    {
        [Category("Tab Control")]
        public VSControls.XPTabControl TabControl
        {
            get { return Control as VSControls.XPTabControl; }
        }

        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Control.ControlCollection Controls
        {
            get { return TabControl.Controls; }
        }

        [Category("Tab Control")]
        [RefreshProperties(RefreshProperties.All)]
        [Localizable(true)]
        public TabAlignment TabControlAlignment
        {
            get { return TabControl.Alignment; }
            set { TabControl.Alignment = value; }
        }

        [Category("Tab Control")]
        [DefaultValue(-1)]
        [Browsable(false)]
        public int TabControlSelectedIndex
        {
            get { return TabControl.SelectedIndex; }
            set { TabControl.SelectedIndex = value; }
        }

        [Category("Tab Control")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Browsable(false)]
        public TabPage TabControlSelectedTab
        {
            get { return TabControl.SelectedTab; }
            set { TabControl.SelectedTab = value; }
        }

        [Category("Tab Control")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Editor("System.Windows.Forms.Design.TabPageCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
        public TabControl.TabPageCollection TabControlTabPages
        {
            get { return TabControl.TabPages; }
        }

        public ToolStripTabControl() :
            base(CreateControlInstance())
        {
        }

        private static VSControls.XPTabControl CreateControlInstance()
        {
            VSControls.XPTabControl t = new VSControls.XPTabControl();
            //t.DrawMode = TabDrawMode.OwnerDrawFixed;
            return t;
        }

        /*protected override void OnSubscribeControlEvents(Control c)
        {
            // Call the base so the base events are connected.
            base.OnSubscribeControlEvents(c);

            TabControl tabControl = c as TabControl;
            tabControl.DrawItem += new DrawItemEventHandler(TabControl_DrawItem);
        }

        protected override void OnUnsubscribeControlEvents(Control c)
        {
            // Call the base method so the basic events are unsubscribed.
            base.OnUnsubscribeControlEvents(c);

            TabControl tabControl = c as TabControl;
            tabControl.DrawItem -= new DrawItemEventHandler(TabControl_DrawItem);
        }

        private void TabControl_DrawItem(object sender, DrawItemEventArgs e)
        {
            using (Brush brush = new SolidBrush(SystemColors.Control))
            {
                e.Graphics.FillRectangle(brush, e.Bounds);
            }
        }*/
    }

    /*internal class ToolStripTabControlDesigner : ComponentDocumentDesigner
    {
        public override void Initialize(IComponent component)
        {
            base.Initialize(component);

            IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost;
            if (host == null)
                return;

            IRootDesigner rootDesigner = host.GetDesigner(host.RootComponent) as IRootDesigner;
            if (rootDesigner == null)
                return;

            Object viewDefault = rootDesigner.GetView(ViewTechnology.Default);
            Control view = viewDefault as Control;
            if (view == null)
                return;
        }
    }*/
}
